<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
		//登陆
    public function login()
	{
			$this->display();	
    }

	public function checkLogin($uname,$upwd,$verify){

		 $uname_lenth=strlen($uname);
		 $password = md5($upwd);
		 $h=$this->check_verify($verify);
         if($uname_lenth<11)
		 {
			$row=M('t_agent')->where("accounts='$uname' AND password='$password'")->find();
		 }
		 elseif($uname_lenth==11)
		 {
		 	$row=M('t_agent')->where("phone='$uname' AND password='$password'")->find();
		 }

		$data = array();  
		
		if(!empty($row) && $h != 0  && $row['agencylv'] ==100){  
		    $data['state'] = 1;
		    session('accounts',$row['accounts']);
			session('password',$row['password']);
			session('phone',$row['phone']);
			session('agencylv',$row['agencylv']);
			session('regtime',$row['regtime']);
			session('gems',$row['gems']);
			session('ip',$row['ip']);
			$t_agent->ip=get_client_ip();
			
		            
		}elseif(!empty($row) && $h == 0){
		    $data['state'] = 2;  
		}elseif(!empty($row) && $row['agencylv'] !=100){
            $data['state'] = 3; 
		}else{
			$data['state'] = 0; 
		}  
	
		$this->ajaxReturn($data); 
	} 

	public function Verify(){	
	$Verify =     new \Think\Verify();// 设置验证码字符为纯数字
	$Verify->codeSet = '0123456789';
	$Verify->length   = 4;
	$Verify->entry();
	}
	
	
	function check_verify($code, $id = ''){
		$verify = new \Think\Verify();
		return $verify->check($code, $id);
		}
	public function logint()
	{
		
			session_destroy();
			echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
			echo "<script type='text/javascript'>alert('退出成功');location.href='login.html'</script>";die;
		
	}
}

?>
